
# setup -------------------------------------------------------------------

## please set the working directory
path = "output/figures/"


###### Making Figure 1: the Treatment Variation Plot ######
# West
# Plot Title
title <- paste0("Green Parties in Parliament (Western Germany)")

# Function to plot
p <- ggplot(aes(
    y = as_factor(ags_num),
    x = as_factor(time_id),
    fill = as_factor(greens_in_st_parl)
),
data = btw_west) +
    geom_raster(hjust =0.5,
                vjust =0.5) +
    ggtitle(title) +
    xlab("Election") +
    ylab("Landkreis") +
    scale_fill_manual(
        values = c("lightgrey", "seagreen"),
        name = "",
        labels = c(
            "Out of State Parliament (Control)",
            "In State Parliament (Treatment)"
        )
    ) +
    scale_x_discrete(
        labels = c(
            "1" = "1953",
            "2" = "1957",
            "3" = "1961",
            "4" = "1965",
            "5" = "1969",
            "6" = "1972",
            "7" = "1976",
            "8" = "1980",
            "9" = "1983",
            "10" = "1987",
            "11" = "1990",
            "12" = "1994",
            "13" = "1998",
            "14" = "2002",
            "15" = "2005",
            "16" = "2009",
            "17" = "2013",
            "18" = "2017"
        )
    ) +
    theme_hanno()+
    theme(
        legend.position = "bottom",
        axis.text.y = element_blank(),
        axis.ticks.y = element_blank(),
        axis.text.x = element_text(
            angle = 0,
            size = 6.5,
            vjust = 0.5
        )
    ) +
    geom_hline(
        yintercept = 0.5 + 0:324,
        colour = "white",
        linewidth = 0.1
    ) +
    panel_border(remove = T)
p
# save plot
ggsave(
    file = paste0(path, "fig_a1.png"),
    height = 6,
    width = 10,
    p,
    dpi = 600,
    device = "png"
)

# East
# Plot Title
title <- paste0("Green Parties in Parliament (Eastern Germany)")

# Function to plot
p <- ggplot(aes(
    y = as_factor(ags_num),
    x = as_factor(time_id),
    fill = as_factor(greens_in_st_parl)
),
data = btw_east) +
    geom_raster(hjust =0.5,
                vjust =0) +
    ggtitle(title) +
    xlab("Election") +
    ylab("Landkreis") +
    scale_fill_manual(
        values = c("lightgrey", "seagreen"),
        name = "",
        labels = c(
            "Out of State Parliament (Control)",
            "In State Parliament (Treatment)"
        )
    ) +
    scale_x_discrete(
        position = "bottom",
        labels = c(
            "11" = "1990",
            "12" = "1994",
            "13" = "1998",
            "14" = "2002",
            "15" = "2005",
            "16" = "2009",
            "17" = "2013",
            "18" = "2017"
        )
    ) +
    theme_hanno() +
    theme(
        legend.position = "bottom",
        axis.text.y = element_blank(),
        axis.ticks.y = element_blank(),
        axis.text.x = element_text(
            angle = 0,
            size = 6.5,
            vjust = 0.5
        )
    ) +
    geom_hline(
        yintercept = 0.5 + 0:324,
        colour = "white",
        linewidth = 0.05
    ) +
    panel_border(remove = T)

p
# save plot
ggsave(
    file = paste0(path, "fig_a2.png"),
    height = 6,
    width = 10,
    dpi = 600,
    p,
    device = "png"
)



